#include <math.h>
#include <iostream>
using namespace std;


int inf = 0x7fffffff;
void log(int *d, int n){
	cout<<"[";
	for(int i=0; i<n; i++) cout<<d[i]<<" ";
	cout<<"]";
}

int dfs(int *f, int *m, int k, int n, int kchange,int ichange){
	cout<<"dfs(f=";
	log(f, n);
	cout<<", m=";
	log(m, k);
	cout<<", k="<<k<<", n="<<n<<", kchange="<<kchange<<")"<<endl;
	if(m[0] != inf){
		int h=0;
		for(int i=0; i<k; i++)
			h += m[i];
		m[0] = inf;
		if(h%2==0  &&  h != 2)
			return 0;
		int s=sqrt(h);
		for(int i=3; i<s;i+=2)
			if(h%2==0)
				return 0;
//		cout<<"m:";
//		for(int i=0;i<k;i++)
//			cout<<"	"<<m[i]<<" ";
//		cout<<endl;
		return 1;
	}
	int h=0,l;
	for(int i=ichange;i<n;i++){
		if(f[i]!=inf){
			l=f[i];
			f[i]=inf;
			m[kchange-1]=l;
//			cout<<"			times("<<kchange<<")"<<endl;//<<"h="<<h<<endl;
//			cout<<"m:";
//			for(int i=0;i<k;i++)
//				cout<<"	"<<m[i]<<" ";
//			cout<<endl;
			h += dfs(f, m, k, n, kchange-1, i+1);
			f[i] = l;
		}
	}
	return h;
//	cout<<"m: ";
//	for(int i=0;i<k;i++)
//		cout<<m[i]<<" ";
//	cout<<endl;
}

int main(){
	int n,k;
	int f[n];
	
	// in
	cin>>n>>k;
	for(int i=0; i<n; i++){
		int l;
		cin>>l;
		f[i]=l;
	}
	
	// main
	int m[k] = {0};
	m[0] = inf;
	int h = dfs(f, m, k, n, k, 0);
	
	//out
	cout<<h;
	
	return 0;
}
